<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
  <meta name="theme-color" content="#222">
  <meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

  <link rel="stylesheet" href="/css/main.css">



  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

  <script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {
      "hostname": "holidaypenguin.gitee.io",
      "root": "/",
      "images": "/images",
      "scheme": "Mist",
      "version": "8.2.2",
      "exturl": false,
      "sidebar": {
        "position": "right",
        "display": "always",
        "padding": 18,
        "offset": 12
      },
      "copycode": true,
      "bookmark": {
        "enable": false,
        "color": "#222",
        "save": "auto"
      },
      "fancybox": false,
      "mediumzoom": false,
      "lazyload": false,
      "pangu": false,
      "comments": {
        "style": "tabs",
        "active": null,
        "storage": true,
        "lazyload": false,
        "nav": null
      },
      "motion": {
        "enable": true,
        "async": true,
        "transition": {
          "post_block": "fadeIn",
          "post_header": "fadeInDown",
          "post_body": "fadeInDown",
          "coll_header": "fadeInLeft",
          "sidebar": "slideUpIn"
        }
      },
      "prism": false,
      "i18n": {
        "placeholder": "搜索...",
        "empty": "没有找到任何搜索结果：${query}",
        "hits_time": "找到 ${hits} 个搜索结果（用时 ${time} 毫秒）",
        "hits": "找到 ${hits} 个搜索结果"
      },
      "path": "/search.xml",
      "localsearch": {
        "enable": true,
        "trigger": "auto",
        "top_n_per_article": 1,
        "unescape": false,
        "preload": false
      }
    };
  </script>
  <meta property="og:type" content="article">
  <meta property="og:title" content="JS数组高端玩法">
  <meta property="og:url" content="https://holidaypenguin.gitee.io/blob/2019-05-23-js-array-high-end-play-method/index.html">
  <meta property="og:site_name" content="HolidayPenguin">
  <meta property="og:locale" content="zh_CN">
  <meta property="article:published_time" content="2019-05-23T12:24:43.000Z">
  <meta property="article:modified_time" content="2019-05-23T12:24:43.000Z">
  <meta property="article:author" content="holidaypenguin">
  <meta property="article:tag" content="JavaScript">
  <meta property="article:tag" content="Array">
  <meta name="twitter:card" content="summary">


  <link rel="canonical" href="https://holidaypenguin.gitee.io/blob/2019-05-23-js-array-high-end-play-method/">


  <script class="page-configurations">
    // https://hexo.io/docs/variables.html
    CONFIG.page = {
      sidebar: "",
      isHome: false,
      isPost: true,
      lang: 'zh-CN'
    };
  </script>
  <title>JS数组高端玩法 | HolidayPenguin</title>





  <noscript>
    <style>
      body {
        margin-top: 2rem;
      }

      .use-motion .menu-item,
      .use-motion .sidebar,
      .use-motion .post-block,
      .use-motion .pagination,
      .use-motion .comments,
      .use-motion .post-header,
      .use-motion .post-body,
      .use-motion .collection-header {
        visibility: visible;
      }

      .use-motion .header,
      .use-motion .site-brand-container .toggle,
      .use-motion .footer {
        opacity: initial;
      }

      .use-motion .site-title,
      .use-motion .site-subtitle,
      .use-motion .custom-logo-image {
        opacity: initial;
        top: initial;
      }

      .use-motion .logo-line {
        transform: scaleX(1);
      }

      .search-pop-overlay,
      .sidebar-nav {
        display: none;
      }

      .sidebar-panel {
        display: block;
      }
    </style>
  </noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner">
        <div class="site-brand-container">
          <div class="site-nav-toggle">
            <div class="toggle" aria-label="切换导航栏" role="button">
              <span class="toggle-line"></span>
              <span class="toggle-line"></span>
              <span class="toggle-line"></span>
            </div>
          </div>

          <div class="site-meta">

            <a href="/" class="brand" rel="start">
              <i class="logo-line"></i>
              <h1 class="site-title">HolidayPenguin</h1>
              <i class="logo-line"></i>
            </a>
          </div>

          <div class="site-nav-right">
            <div class="toggle popup-trigger">
              <i class="fa fa-search fa-fw fa-lg"></i>
            </div>
          </div>
        </div>



        <nav class="site-nav">
          <ul class="main-menu menu">
            <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
            <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
            <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
            <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
            <li class="menu-item menu-item-search">
              <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
              </a>
            </li>
          </ul>
        </nav>



        <div class="search-pop-overlay">
          <div class="popup search-popup">
            <div class="search-header">
              <span class="search-icon">
                <i class="fa fa-search"></i>
              </span>
              <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off" maxlength="80" placeholder="搜索..." spellcheck="false" type="search" class="search-input">
              </div>
              <span class="popup-btn-close" role="button">
                <i class="fa fa-times-circle"></i>
              </span>
            </div>
            <div class="search-result-container no-result">
              <div class="search-result-icon">
                <i class="fa fa-spinner fa-pulse fa-5x"></i>
              </div>
            </div>

          </div>
        </div>

      </div>


      <div class="toggle sidebar-toggle" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
      </div>

      <aside class="sidebar">

        <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
          <ul class="sidebar-nav">
            <li class="sidebar-nav-toc">
              文章目录
            </li>
            <li class="sidebar-nav-overview">
              站点概览
            </li>
          </ul>

          <div class="sidebar-panel-container">
            <!--noindex-->
            <div class="post-toc-wrap sidebar-panel">
              <div class="post-toc animated">
                <ol class="nav">
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%89%81%E5%B9%B3%E5%8C%96n%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="nav-number">1.</span> <span class="nav-text">1.扁平化n维数组</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%8E%BB%E9%87%8D"><span class="nav-number">2.</span> <span class="nav-text">2.去重</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%8E%92%E5%BA%8F"><span class="nav-number">3.</span> <span class="nav-text">3.排序</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%9C%80%E5%A4%A7%E5%80%BC"><span class="nav-number">4.</span> <span class="nav-text">4.最大值</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E6%B1%82%E5%92%8C"><span class="nav-number">5.</span> <span class="nav-text">5.求和</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E5%90%88%E5%B9%B6"><span class="nav-number">6.</span> <span class="nav-text">6.合并</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E5%80%BC"><span class="nav-number">7.</span> <span class="nav-text">7.判断是否包含值</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#8-%E7%B1%BB%E6%95%B0%E7%BB%84%E8%BD%AC%E5%8C%96"><span class="nav-number">8.</span> <span class="nav-text">8.类数组转化</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#9-%E6%AF%8F%E4%B8%80%E9%A1%B9%E8%AE%BE%E7%BD%AE%E5%80%BC"><span class="nav-number">9.</span> <span class="nav-text">9.每一项设置值</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#10-%E6%AF%8F%E4%B8%80%E9%A1%B9%E6%98%AF%E5%90%A6%E6%BB%A1%E8%B6%B3"><span class="nav-number">10.</span> <span class="nav-text">10.每一项是否满足</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#11-%E6%9C%89%E4%B8%80%E9%A1%B9%E6%BB%A1%E8%B6%B3"><span class="nav-number">11.</span> <span class="nav-text">11.有一项满足</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#12-%E8%BF%87%E6%BB%A4%E6%95%B0%E7%BB%84"><span class="nav-number">12.</span> <span class="nav-text">12.过滤数组</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#13-%E5%AF%B9%E8%B1%A1%E5%92%8C%E6%95%B0%E7%BB%84%E8%BD%AC%E5%8C%96"><span class="nav-number">13.</span> <span class="nav-text">13.对象和数组转化</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%93%E8%AF%AD"><span class="nav-number">14.</span> <span class="nav-text">结语</span></a></li>
                </ol>
              </div>
            </div>
            <!--/noindex-->

            <div class="site-overview-wrap sidebar-panel">
              <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
                <p class="site-author-name" itemprop="name">holidaypenguin</p>
                <div class="site-description" itemprop="description"></div>
              </div>
              <div class="site-state-wrap site-overview-item animated">
                <nav class="site-state">
                  <div class="site-state-item site-state-posts">
                    <a href="/archives/">

                      <span class="site-state-item-count">138</span>
                      <span class="site-state-item-name">日志</span>
                    </a>
                  </div>
                  <div class="site-state-item site-state-categories">
                    <a href="/categories/">

                      <span class="site-state-item-count">26</span>
                      <span class="site-state-item-name">分类</span></a>
                  </div>
                  <div class="site-state-item site-state-tags">
                    <a href="/tags/">

                      <span class="site-state-item-count">234</span>
                      <span class="site-state-item-name">标签</span></a>
                  </div>
                </nav>
              </div>
              <div class="links-of-author site-overview-item animated">
                <span class="links-of-author-item">
                  <a href="https://github.com/holidaypenguin" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;holidaypenguin" rel="noopener" target="_blank"><i class="github fa-fw"></i>GitHub</a>
                </span>
                <span class="links-of-author-item">
                  <a href="mailto:songshipeng2016@gmail.com" title="E-Mail → mailto:songshipeng2016@gmail.com" rel="noopener" target="_blank"><i class="envelope fa-fw"></i>E-Mail</a>
                </span>
              </div>



            </div>
          </div>
        </div>
      </aside>
      <div class="sidebar-dimmer"></div>


    </header>


    <div class="back-to-top" role="button">
      <i class="fa fa-arrow-up"></i>
      <span>0%</span>
    </div>

    <noscript>
      <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
    </noscript>


    <div class="main-inner post posts-expand">





      <div class="post-block">



        <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
          <link itemprop="mainEntityOfPage" href="https://holidaypenguin.gitee.io/blob/2019-05-23-js-array-high-end-play-method/">

          <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
            <meta itemprop="image" content="/images/avatar.gif">
            <meta itemprop="name" content="holidaypenguin">
            <meta itemprop="description" content="">
          </span>

          <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
            <meta itemprop="name" content="HolidayPenguin">
          </span>
          <header class="post-header">
            <h1 class="post-title" itemprop="name headline">
              JS数组高端玩法
            </h1>

            <div class="post-meta-container">
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>

                  <time title="创建时间：2019-05-23 20:24:43" itemprop="dateCreated datePublished" datetime="2019-05-23T20:24:43+08:00">2019-05-23</time>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-folder"></i>
                  </span>
                  <span class="post-meta-item-text">分类于</span>
                  <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                    <a href="/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a>
                  </span>
                </span>


                <span id="/blob/2019-05-23-js-array-high-end-play-method/" class="post-meta-item leancloud_visitors" data-flag-title="JS数组高端玩法" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
              </div>

              <div class="post-description">
                <!-- more -->
              </div>
            </div>
          </header>




          <div class="post-body" itemprop="articleBody">
            <p>前言</p>
            <p>本文主要从应用来讲数组api的一些骚操作;<br>如一行代码扁平化n维数组、数组去重、求数组最大值、数组求和、排序、对象和数组的转化等；<br>上面这些应用场景你可以用一行代码实现？</p>
            <h2 id="1-扁平化n维数组"><a href="#1-扁平化n维数组" class="headerlink" title="1.扁平化n维数组"></a>1.扁平化n维数组</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,[<span class="number">2</span>,<span class="number">3</span>]].flat(<span class="number">2</span>) <span class="comment">//[1,2,3]</span></span><br><span class="line">[<span class="number">1</span>,[<span class="number">2</span>,<span class="number">3</span>,[<span class="number">4</span>,<span class="number">5</span>]].flat(<span class="number">3</span>) <span class="comment">//[1,2,3,4,5]</span></span><br><span class="line">[<span class="number">1</span>,[<span class="number">2</span>,<span class="number">3</span>,[<span class="number">4</span>,<span class="number">5</span>]]].toString()  <span class="comment">//&#x27;1,2,3,4,5&#x27;</span></span><br><span class="line">[<span class="number">1</span>[<span class="number">2</span>,<span class="number">3</span>,[<span class="number">4</span>,<span class="number">5</span>[...]].flat(<span class="literal">Infinity</span>) <span class="comment">//[1,2,3,4...n]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>Array.flat(n)是ES10扁平数组的api,n表示维度,n值为Infinity时维度为无限大</p>
            <ol start="2">
              <li>开始篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">flatten</span>(<span class="params">arr</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">while</span>(arr.some(<span class="function"><span class="params">item</span>=&gt;</span><span class="built_in">Array</span>.isArray(item))) &#123;</span><br><span class="line">    arr = [].concat(...arr);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> arr;</span><br><span class="line">&#125;</span><br><span class="line">flatten([<span class="number">1</span>,[<span class="number">2</span>,<span class="number">3</span>]]) <span class="comment">//[1,2,3]</span></span><br><span class="line">flatten([<span class="number">1</span>,[<span class="number">2</span>,<span class="number">3</span>,[<span class="number">4</span>,<span class="number">5</span>]]) <span class="comment">//[1,2,3,4,5]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>实质是利用递归和数组合并方法concat实现扁平</p>
            <h2 id="2-去重"><a href="#2-去重" class="headerlink" title="2.去重"></a>2.去重</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Array</span>.from(<span class="keyword">new</span> <span class="built_in">Set</span>([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">4</span>])) <span class="comment">//[1,2,3,4]</span></span><br><span class="line">[...new <span class="built_in">Set</span>([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">4</span>])] <span class="comment">//[1,2,3,4]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>set是ES6新出来的一种一种定义不重复数组的数据类型<br>Array.from是将类数组转化为数组<br>…是扩展运算符,将set里面的值转化为字符串</p>
            <ol start="2">
              <li>开始篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Array</span>.prototype.distinct = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="keyword">var</span> arr = <span class="built_in">this</span>,  result = [],  i,  j,  len = arr.length;</span><br><span class="line">  <span class="keyword">for</span>(i = <span class="number">0</span>; i &lt; len; i++)&#123;</span><br><span class="line">    <span class="keyword">for</span>(j = i + <span class="number">1</span>; j &lt; len; j++)&#123;</span><br><span class="line">      <span class="keyword">if</span>(arr[i] === arr[j])&#123;</span><br><span class="line">        j = ++i;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    result.push(arr[i]);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">4</span>].distinct(); <span class="comment">//[1,2,3,4]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>取新数组存值,循环两个数组值相比较</p>
            <h2 id="3-排序"><a href="#3-排序" class="headerlink" title="3.排序"></a>3.排序</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].sort(<span class="function">(<span class="params">a, b</span>) =&gt;</span> a - b); <span class="comment">// [1, 2,3,4],默认是升序</span></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].sort(<span class="function">(<span class="params">a, b</span>) =&gt;</span> b - a); <span class="comment">// [4,3,2,1] 降序</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>sort是js内置的排序方法,参数为一个函数<br>2. 开始篇<br>冒泡排序:</p>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Array</span>.prototype.bubleSort=<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> arr=<span class="built_in">this</span>,</span><br><span class="line">      len = arr.length;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> outer = len; outer &gt;= <span class="number">2</span>; outer--) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> inner = <span class="number">0</span>; inner &lt;= outer - <span class="number">1</span>; inner++) &#123;</span><br><span class="line">      <span class="keyword">if</span> (arr[inner] &gt; arr[inner + <span class="number">1</span>]) &#123;</span><br><span class="line">        <span class="comment">//升序</span></span><br><span class="line">        [arr[inner], arr[inner + <span class="number">1</span>]] = [arr[inner + <span class="number">1</span>], arr[inner]];</span><br><span class="line">        <span class="built_in">console</span>.log([arr[inner], arr[inner + <span class="number">1</span>]]);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> arr;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].bubleSort() <span class="comment">//[1,2,3,4]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>选择排序</p>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Array</span>.prototype.selectSort=<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> arr=<span class="built_in">this</span>,</span><br><span class="line">      len = arr.length;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>, len = arr.length; i &lt; len; i++) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> j = i, len = arr.length; j &lt; len; j++) &#123;</span><br><span class="line">      <span class="keyword">if</span> (arr[i] &gt; arr[j]) &#123;</span><br><span class="line">        [arr[i], arr[j]] = [arr[j], arr[i]];</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> arr;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].selectSort() <span class="comment">//[1,2,3,4] </span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <h2 id="4-最大值"><a href="#4-最大值" class="headerlink" title="4.最大值"></a>4.最大值</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Math</span>.max(...[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>]) <span class="comment">//4</span></span><br><span class="line"><span class="built_in">Math</span>.max.apply(<span class="built_in">this</span>,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>]) <span class="comment">//4</span></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].reduce( <span class="function">(<span class="params">prev, cur,curIndex,arr</span>)=&gt;</span> &#123; </span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Math</span>.max(prev,cur);</span><br><span class="line">&#125;,<span class="number">0</span>) <span class="comment">//4</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>Math.max()是Math对象内置的方法,参数是字符串;<br>reduce是ES5的数组api,参数有函数和默认初始值;<br>函数有四个参数,pre(上一次的返回值),cur(当前值),curIndex(当前值索引),arr(当前数组)</p>
            <ol start="2">
              <li>开始篇<br>先排序再取值</li>
            </ol>
            <h2 id="5-求和"><a href="#5-求和" class="headerlink" title="5.求和"></a>5.求和</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].reduce(<span class="function"><span class="keyword">function</span> (<span class="params">prev, cur</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> prev + cur;</span><br><span class="line">&#125;,<span class="number">0</span>) <span class="comment">//10 </span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <ol start="2">
              <li>开始篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">sum</span>(<span class="params">arr</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> len = arr.length;</span><br><span class="line">  <span class="keyword">if</span>(len == <span class="number">0</span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">  &#125; <span class="keyword">else</span> <span class="keyword">if</span> (len == <span class="number">1</span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> arr[<span class="number">0</span>];</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> arr[<span class="number">0</span>] + sum(arr.slice(<span class="number">1</span>));</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">sum([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>]) <span class="comment">//10</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>利用slice截取改变数组,再利用递归求和</p>
            <h2 id="6-合并"><a href="#6-合并" class="headerlink" title="6.合并"></a>6.合并</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].concat([<span class="number">5</span>,<span class="number">6</span>]) <span class="comment">//[1,2,3,4,5,6]</span></span><br><span class="line">[...[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>],...[<span class="number">4</span>,<span class="number">5</span>]] <span class="comment">//[1,2,3,4,5,6]</span></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].push.apply([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>],[<span class="number">5</span>,<span class="number">6</span>]) <span class="comment">//[1,2,3,4,5,6]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <ol start="2">
              <li>开始篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="keyword">let</span> arr=[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>];</span><br><span class="line">[<span class="number">5</span>,<span class="number">6</span>].map(<span class="function"><span class="params">item</span>=&gt;</span>&#123;</span><br><span class="line">  arr.push(item)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">//arr值为[1,2,3,4,5,6],注意不能直接return出来,return后只会返回[5,6]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <h2 id="7-判断是否包含值"><a href="#7-判断是否包含值" class="headerlink" title="7.判断是否包含值"></a>7.判断是否包含值</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].includes(<span class="number">4</span>) <span class="comment">//false</span></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].indexOf(<span class="number">4</span>) <span class="comment">//-1 如果存在换回索引</span></span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].find(<span class="function">(<span class="params">item</span>)=&gt;</span>item===<span class="number">3</span>)) <span class="comment">//3 如果数组中无值返回undefined</span></span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].findIndex(<span class="function">(<span class="params">item</span>)=&gt;</span>item===<span class="number">3</span>)) <span class="comment">//2 如果数组中无值返回-1</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>includes(),find(),findIndex()是ES6的api</p>
            <ol start="2">
              <li>开始篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].some(<span class="function"><span class="params">item</span>=&gt;</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> item===<span class="number">3</span></span><br><span class="line">&#125;) <span class="comment">//true 如果不包含返回false</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <h2 id="8-类数组转化"><a href="#8-类数组转化" class="headerlink" title="8.类数组转化"></a>8.类数组转化</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Array</span>.prototype.slice.call(<span class="built_in">arguments</span>) <span class="comment">//arguments是类数组(伪数组)</span></span><br><span class="line"><span class="built_in">Array</span>.prototype.slice.apply(<span class="built_in">arguments</span>)</span><br><span class="line"><span class="built_in">Array</span>.from(<span class="built_in">arguments</span>)</span><br><span class="line">[...arguments]</span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>类数组:表示有length属性,但是不具备数组的方法<br>call,apply:是改变slice里面的this指向arguments,所以arguments也可调用数组的方法<br>Array.from是将类似数组或可迭代对象创建为数组<br>…是将类数组扩展为字符串,再定义为数组</p>
            <ol start="2">
              <li>开始篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Array</span>.prototype.slice = <span class="function"><span class="keyword">function</span>(<span class="params">start,end</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">var</span> result = <span class="keyword">new</span> <span class="built_in">Array</span>();</span><br><span class="line">  start = start || <span class="number">0</span>;</span><br><span class="line">  end = end || <span class="built_in">this</span>.length; <span class="comment">//this指向调用的对象，当用了call后，能够改变this的指向，也就是指向传进来的对象，这是关键</span></span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">var</span> i = start; i &lt; end; i++)&#123;</span><br><span class="line">    result.push(<span class="built_in">this</span>[i]);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> result;</span><br><span class="line">&#125; </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <h2 id="9-每一项设置值"><a href="#9-每一项设置值" class="headerlink" title="9.每一项设置值"></a>9.每一项设置值</h2>
            <ol>
              <li>终极篇</li>
            </ol>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].fill(<span class="literal">false</span>) <span class="comment">//[false,false,false] </span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>fill是ES6的方法<br>2. 开始篇</p>
            <figure class="highlight plain">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[1,2,3].map(() &#x3D;&gt; 0)</span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <h2 id="10-每一项是否满足"><a href="#10-每一项是否满足" class="headerlink" title="10.每一项是否满足"></a>10.每一项是否满足</h2>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].every(<span class="function"><span class="params">item</span>=&gt;</span>&#123;<span class="keyword">return</span> item&gt;<span class="number">2</span>&#125;) <span class="comment">//false</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>every是ES5的api,每一项满足返回 true</p>
            <h2 id="11-有一项满足"><a href="#11-有一项满足" class="headerlink" title="11.有一项满足"></a>11.有一项满足</h2>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].some(<span class="function"><span class="params">item</span>=&gt;</span>&#123;<span class="keyword">return</span> item&gt;<span class="number">2</span>&#125;) <span class="comment">//true</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>some是ES5的api,有一项满足返回 true</p>
            <h2 id="12-过滤数组"><a href="#12-过滤数组" class="headerlink" title="12.过滤数组"></a>12.过滤数组</h2>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].filter(<span class="function"><span class="params">item</span>=&gt;</span>&#123;<span class="keyword">return</span> item&gt;<span class="number">2</span>&#125;) <span class="comment">//[3]</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p>filter是ES5的api,返回满足添加的项的数组</p>
            <h2 id="13-对象和数组转化"><a href="#13-对象和数组转化" class="headerlink" title="13.对象和数组转化"></a>13.对象和数组转化</h2>
            <figure class="highlight js">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="built_in">Object</span>.keys(&#123;<span class="attr">name</span>:<span class="string">&#x27;张三&#x27;</span>,<span class="attr">age</span>:<span class="number">14</span>&#125;) <span class="comment">//[&#x27;name&#x27;,&#x27;age&#x27;]</span></span><br><span class="line"><span class="built_in">Object</span>.values(&#123;<span class="attr">name</span>:<span class="string">&#x27;张三&#x27;</span>,<span class="attr">age</span>:<span class="number">14</span>&#125;) <span class="comment">//[&#x27;张三&#x27;,14]</span></span><br><span class="line"><span class="built_in">Object</span>.entries(&#123;<span class="attr">name</span>:<span class="string">&#x27;张三&#x27;</span>,<span class="attr">age</span>:<span class="number">14</span>&#125;) <span class="comment">//[[name,&#x27;张三&#x27;],[age,14]]</span></span><br><span class="line"><span class="built_in">Object</span>.fromEntries([name,<span class="string">&#x27;张三&#x27;</span>],[age,<span class="number">14</span>]) <span class="comment">//ES10的api,Chrome不支持 , firebox输出&#123;name:&#x27;张三&#x27;,age:14&#125;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2>
            <p>更多精彩请戳火狼前端小而全的知识归纳</p>
            <p>作者：火狼<br><a target="_blank" rel="noopener" href="https://segmentfault.com/a/1190000018549643">https://segmentfault.com/a/1190000018549643</a></p>

          </div>





          <footer class="post-footer">
            <div class="post-tags">
              <a href="/tags/JavaScript/" rel="tag"># JavaScript</a>
              <a href="/tags/Array/" rel="tag"># Array</a>
            </div>



            <div class="post-nav">
              <div class="post-nav-item">
                <a href="/blob/2019-05-23-catalogue-of-knowledge-points-in-front-end-interview/" rel="prev" title="前端面试知识点目录整理">
                  <i class="fa fa-chevron-left"></i> 前端面试知识点目录整理
                </a>
              </div>
              <div class="post-nav-item">
                <a href="/blob/2019-05-28-sliding-penetration-problem-on-shield-layer-of-moving-end/" rel="next" title="移动端遮罩层上面滑动穿透问题">
                  移动端遮罩层上面滑动穿透问题 <i class="fa fa-chevron-right"></i>
                </a>
              </div>
            </div>
          </footer>
        </article>
      </div>







      <script>
        window.addEventListener('tabs:register', () => {
          let {
            activeClass
          } = CONFIG.comments;
          if (CONFIG.comments.storage) {
            activeClass = localStorage.getItem('comments_active') || activeClass;
          }
          if (activeClass) {
            const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
            if (activeTab) {
              activeTab.click();
            }
          }
        });
        if (CONFIG.comments.storage) {
          window.addEventListener('tabs:click', event => {
            if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
            const commentClass = event.target.classList[1];
            localStorage.setItem('comments_active', commentClass);
          });
        }
      </script>
    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


      <div class="copyright">
        &copy;
        <span itemprop="copyrightYear">2021</span>
        <span class="with-love">
          <i class="fa fa-heart"></i>
        </span>
        <span class="author" itemprop="copyrightHolder">holidaypenguin</span>
      </div>
      <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
      </div>

    </div>
  </footer>


  <script size="300" alpha="0.1" zIndex="-1" src="https://cdn.jsdelivr.net/npm/ribbon.js@1.0.2/dist/ribbon.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
  <script src="/js/love.js"></script>

  <script src="/js/development.js"></script>
  <script src="/js/utils.js"></script>
  <script src="/js/motion.js"></script>
  <script src="/js/schemes/muse.js"></script>
  <script src="/js/next-boot.js"></script>


  <script src="/js/local-search.js"></script>









  <script>
    (function() {
      function leancloudSelector(url) {
        url = encodeURI(url);
        return document.getElementById(url).querySelector('.leancloud-visitors-count');
      }

      function addCount(Counter) {
        const visitors = document.querySelector('.leancloud_visitors');
        const url = decodeURI(visitors.id);
        const title = visitors.dataset.flagTitle;

        Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({
            url
          })))
          .then(response => response.json())
          .then(({
            results
          }) => {
            if (results.length > 0) {
              const counter = results[0];
              leancloudSelector(url).innerText = counter.time + 1;
              Counter('put', '/classes/Counter/' + counter.objectId, {
                  time: {
                    '__op': 'Increment',
                    'amount': 1
                  }
                })
                .catch(error => {
                  console.error('Failed to save visitor count', error);
                });
            } else {
              Counter('post', '/classes/Counter', {
                  title,
                  url,
                  time: 1
                })
                .then(response => response.json())
                .then(() => {
                  leancloudSelector(url).innerText = 1;
                })
                .catch(error => {
                  console.error('Failed to create', error);
                });
            }
          })
          .catch(error => {
            console.error('LeanCloud Counter Error', error);
          });
      }

      function showTime(Counter) {
        const visitors = document.querySelectorAll('.leancloud_visitors');
        const entries = [...visitors].map(element => {
          return decodeURI(element.id);
        });

        Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({
            url: {
              '$in': entries
            }
          })))
          .then(response => response.json())
          .then(({
            results
          }) => {
            for (let url of entries) {
              const target = results.find(item => item.url === url);
              leancloudSelector(url).innerText = target ? target.time : 0;
            }
          })
          .catch(error => {
            console.error('LeanCloud Counter Error', error);
          });
      }

      const {
        app_id,
        app_key,
        server_url
      } = {
        "enable": true,
        "app_id": "povuqNsSqFodlakVIwtEX5kb-gzGzoHsz",
        "app_key": "zXD40RDtDB3DMtpC89k0AK7g",
        "server_url": null,
        "security": false
      };

      function fetchData(api_server) {
        const Counter = (method, url, data) => {
          return fetch(`${api_server}/1.1${url}`, {
            method,
            headers: {
              'X-LC-Id': app_id,
              'X-LC-Key': app_key,
              'Content-Type': 'application/json',
            },
            body: JSON.stringify(data)
          });
        };
        if (CONFIG.page.isPost) {
          if (CONFIG.hostname !== location.hostname) return;
          addCount(Counter);
        } else if (document.querySelectorAll('.post-title-link').length >= 1) {
          showTime(Counter);
        }
      }

      const api_server = app_id.slice(-9) === '-MdYXbMMI' ? `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com` : server_url;

      if (api_server) {
        fetchData(api_server);
      } else {
        fetch('https://app-router.leancloud.cn/2/route?appId=' + app_id)
          .then(response => response.json())
          .then(({
            api_server
          }) => {
            fetchData('https://' + api_server);
          });
      }
    })();
  </script>



<script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                preloadRatio: 1,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(n){n.imageLazyLoadSetting.processImages=o;var e=n.imageLazyLoadSetting.isSPA,i=n.imageLazyLoadSetting.preloadRatio||1,r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]"));function o(){e&&(r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")));for(var t,a=0;a<r.length;a++)0<=(t=(t=r[a]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(n.innerHeight*i||document.documentElement.clientHeight*i)&&function(){var t,e,n,i,o=r[a];t=o,e=function(){r=r.filter(function(t){return o!==t})},n=new Image,i=t.getAttribute("data-original"),n.onload=function(){t.src=i,e&&e()},t.src!==i&&(n.src=i)}()}o(),n.addEventListener("scroll",function(){var t,e;t=o,e=n,clearTimeout(t.tId),t.tId=setTimeout(function(){t.call(e)},500)})}(this);</script></body>

</html>